#http://www.win4000.com/sjzt/xingganmeinv.html #http://www.win4000.com/mobile.html
import requests
import parsel
base_url='http://www.win4000.com/sjzt/xingganmeinv.html'
headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
    }
response=requests.get(base_url,headers=headers)
data=response.text#文本数据用text
# print(data)
html_data=parsel.Selector(data)#解析数据 数据类型转换
data_list=html_data.xpath('//div[@class="Left_bar"]//ul/li/a/@href').extract()#数据提取
#print(data_list)
for alist in data_list:
    #发送相册的URL地址请求
    response_2=requests.get(alist,headers=headers).text#提取所有数据
    html_2=parsel.Selector(response_2)
    img_url=html_2.xpath('//div[@class="pic-meinv"]/a/img/@src').extract_first()#只提取一个数据
    # print(img_url)
    img_data=requests.get(img_url,headers=headers).content#图片数据用(二进制数据)content
    file_name=img_url.split('/')[-1]
    # print(file_name)
    with open('img\\'+file_name,mode='wb') as f:
        print('正在保存文件',file_name)
        f.write(img_data)